<?php
/**
 * @description 股票列表
 * @author 陈武<chenwu@myhexin.com>
 * @history
 *         2020/4/21 23:27 create
 */
namespace Home\Model;
class StockModel
{
    /**
     * @description 搜索
     * @param int $page
     * @param int $size
     * @param array $where
     * @return mixed
     */
    public function search($page = 1, $size = 10, $where = [])
    {
        return M('stock')->page($page)->limit($size)->where($where)->select();
    }

    /**
     * @description 总条数
     * @param array $where
     * @return int
     */
    public function total($where)
    {
        $result = M('stock')->field('id')->where($where)->select();
        return $result?count($result):0;
    }

    /**
     * @description 更新数据
     * @param array $where 条件
     * @param array $data 具体数据
     * @return bool
     */
    public function update($where, $data)
    {
        return M('stock')->where($where)->save($data);
    }

    /**
     * 字典表
     * @return array
     */
    public function dic()
    {
        $data = [];
        $result = M('stock')->field('id,name')->select();
        if ($result) {
            foreach ($result as $key => $value) {
                $data[$value['id']] = $value['name'];
            }
        }
        return $data;
    }
}